<div class="sm-rightPanel bg-darken">
    <div class="layui-anim layui-anim-upbit">
        <blockquote class="site-text layui-elem-quote">
            <h2>联系我们</h2>
        </blockquote>
        <div class="layui-form" action="">
            <div class="layui-row">
                <div class="sm-form-lg" id="dialog_form" style="overflow: hidden;">
                    <input type="hidden" name="id" value="">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><i>*</i>公司名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="companyName" lay-verify="required" placeholder="请输入公司名称"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><i>*</i>电话</label>
                        <div class="layui-input-block">
                            <input type="text" name="phone" lay-verify="required" placeholder="请输入电话"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><i>*</i>邮箱</label>
                        <div class="layui-input-block">
                            <input type="text" name="email" lay-verify="required" placeholder="请输入邮箱"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">公司地址</label>
                        <div class="layui-input-block">
                            <textarea name="address" maxlength="200" placeholder="请输入公司地址"
                                      class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn" lay-submit lay-filter="addsingle_form">立即提交</button>
                            <button type="button" class="layui-btn  layui-btn-primary" id="add_canl">取消</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['layedit', "upload", "form"], function () {
        var $ = layui.$;
        var form = layui.form;
        form.render();


        initData();

        //取消
        $("#add_canl").click(function () {

        });
        //提交
        form.on('submit(addsingle_form)', function (d) {
            var formData = d.field;
            var data = {};
            data.id = formData.id;
            data.companyName = formData.companyName;
            data.phone = formData.phone;
            data.email = formData.email;
            data.address = formData.address;
            smartAui.ajax({
                url: '/websitecontactus/save',
                data: data,
                loading: true,
                success: function (result) {
                    if (result.success) {
                        layer.msg("保存成功");
                    }
                },
            });
            return false;
        });

        function initData() {
            smartAui.ajax({
                url: '/websitecontactus/info',
                success: function (result) {
                    if (result.success) {
                        if (result.data) {
                            var id = result.data.id;
                            var companyName = result.data.companyName;
                            var phone = result.data.phone;
                            var email = result.data.email;
                            var address = result.data.address;

                            $("input[name='id']").val(id);
                            $("input[name='companyName']").val(companyName);
                            $("input[name='phone']").val(phone);
                            $("input[name='email']").val(email);
                            $("textarea[name='address']").text(address);
                        }
                    }
                },
            });
        }

    });
</script>